'''此模块用来封装接口访问方法'''
#以下两行代码用来调试数据
# import requests
# from JK_UI.config.config import *
# session=requests.Session()

class Api:
    #用单例模式方法封装一个session对象
    @classmethod
    def set_session(cls,session):
        cls.session=session
    @classmethod
    def get_session(cls):
        return cls.session
    #封装接口访问的方法
    @classmethod
    def send_api(cls,api_ele):
        # api_ele=['post','url','data','head']
        type=[['post','put','patch'],['get','delete','head','optins']]
        if api_ele[0] in type[0]:
            cls.response=cls.session.request(method=api_ele[0],url=api_ele[1],
                                               data=api_ele[2],headers=api_ele[3])
        elif api_ele[0] in type[1]:
            cls.response=cls.session.request(method=api_ele[0],url=api_ele[1],
                                               params=api_ele[2],headers=api_ele[3])
        return cls.response
    #断言的方法
    def api_text_assert(self):
        self.value=self.response.text   #获取文本值断言
        return self.value

    def api_json_assert(self):
        self.value=self.response.json()
        return self.value
if __name__ == '__main__':
    a=Api()
    a.set_session(session=session)
    a.get_session()
    cms_login=['post',cms_login_url,cms_login_data,cms_login_headers]
    a.send_api(api_ele=cms_login)
    a.api_json_assert()